package org.zf.database.domain;

import cn.hutool.core.util.StrUtil;
import lombok.*;
import org.zf.database.consts.FieldType;

import java.io.Serializable;

/**
 * 字段描述信息
 */
@Data
@ToString
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
public class FieldInfo implements Serializable
{
    private TableInfo tableInfo;
    private String fieldName;
    private String sourceType;
    private FieldType commonType;
    private Integer length;
    private Integer precision;
    private Boolean nullable = true;
    private String comment;
    private Boolean isPK = false;
    // 组合主键排序
    private Integer pkInd;
    private String defaultStr;

    public FieldInfo(String fieldName)
    {
        this.fieldName = fieldName;
    }


    public FieldInfo(TableInfo tableInfo, String fieldName, FieldType commonType)
    {
        this.tableInfo = tableInfo;
        this.fieldName = fieldName;
        this.commonType = commonType;
    }

    public void setSourceType(String sourceType)
    {
        if (StrUtil.isNotEmpty(sourceType))
        {
            int i = sourceType.indexOf("(");
            this.sourceType = i != -1 ? sourceType.substring(0, i) : sourceType;
        }
    }

//    public String getFieldName()
//    {
//        return (fieldName+"").toUpperCase();
//    }
}
